using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.User;

public partial class User_Logout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LogUserViewedHistory();
        }

        if (Session[CE.Global.General.UserId] != null)
        {
            //if (ClearUserLoginCached(Session[CE.Global.General.UserId].ToString()))
            //{

            if (Session[CE.Global.General.LoginHistoryId] != null)
                UpdateLogInHistory(Convert.ToInt64(Session[CE.Global.General.LoginHistoryId].ToString()));

            AccountStatusDB _accountstatusdb = new AccountStatusDB();
            _accountstatusdb.UpdateLoginStatus(Convert.ToInt64(Session[CE.Global.General.UserId].ToString()));


            CE.Global.General.ClearAllSession(this.Page, "LOGOUT");


            Response.Redirect("~/SiteUserSecureLogin.aspx");

        }
        else
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }


    }

    private void LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        _userviewdb.LogViewedHistory("USR", Request, "User log out.");
    }

    protected void UpdateLogInHistory(Int64 LogHisId)
    {
        LoginHistory _loghis = new LoginHistory();
        LoginHistoryDB _loghisdb = new LoginHistoryDB();

        _loghis.LoginHisId = LogHisId;
        _loghis.EndTime = DateTime.Now;
        _loghis.Status = "LOGIN/LOGOUT";
        _loghis.IsExpired = false;
        _loghisdb.Insert(_loghis);

        _loghis = null;
        _loghisdb = null;

    }


}
